<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>党建基础设置</title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" type="text/css" href="../css/base.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/laydate/skins/default/laydate.css"/>
    <link rel="stylesheet" type="text/css" href="../css/dept/deptManagement.css"/>
    <link rel="stylesheet" type="text/css" href="../lib/easyui/themes/easyui.css"/>
    <link rel="stylesheet" type="text/css" hcont_rigref="../lib/easyui/themes/icon.css"/>
    <link rel="stylesheet" type="text/css" href="../css/news/center.css"/>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../js/base/base.js"></script>
    <script src="/lib/layer/layer.js?20201106"></script>
    <script src="../../lib/laydate/laydate.js"></script>

    <script>
        //添加人员
        function selPriv(id) {
            user_id = id;
            $.popWindow("../../common/selectUser");
        }

        function clearPriv(id) {
            $("#" + id).val("");
            $("#" + id).attr('user_id', '');
            $("#" + id).attr('dataid', '');
        }
    </script>
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #f6f7f9;
        }

        table {
            border-collapse: collapse;
            border: 1px solid #dedede;
            width: 1100px;
            background-color: #ffffff;
            margin: 35px auto;
        }

        td {
            text-align: center;
            width: 50%!important;
            border: 1px solid #dedede;
            font-size: 11pt;
        }

        textarea {
            height: 56px;
            width: 300px;
            background: #e0e0e0;
            margin: 2px 0 0 2px;
        }

        .btn {
            width: 70px;
            height: 24px;
            margin: 0 auto;
            padding: 2px 0 2px 0;
            background: url("/img/confirm.png") no-repeat;
        }

        input {
            position: relative;
            top: -1px;
        }

        button {
            background: transparent;
            margin-left: 33px;
            line-height: 26px;
            font-size: 11pt;
        }

        .add {
            color: #207bd6;
        }

        .empty {
            color: #9aa9b8;
        }

        .head {
            height: 45px;
            border-bottom: 1px solid #9E9E9E;
        }

        h1 {
            line-height: 45px;
            font-size: 22px;
        }

        input[type="checkbox"], input[type="radio"] {
            background: transparent;
            border: 0;
        }
        .search_inline {
            width: 310px;
            height: 32px;
            display: inline-block;
            position: relative;
        }
        .search_inline .search_inline_item {
            width: 100%;
            box-sizing: border-box;
            height: 32px;
        }
        .list {
            width: 40px;
            height: 31px;
            background: #f3f3f3;
            border: 1px solid #ccc;
            vertical-align: middle;
            position: absolute;
            right: 0px;
            top: 0px;
            border-radius: 0px 3px 3px 0px;
        }
        .sel {
            width: 100%;
            max-height: 250px;
            position: absolute;
            top: 100%;
            left: 0;
            overflow: auto;
            background: #fff;
            border: 1px solid #e2e3e3;
            display: none;
            z-index: 1;
        }
        .canchoose:hover{
            background: #2b7edf;
            color: #fff;
        }
        select {
            width: 160px;
            margin-left: 50px;
        }
    </style>
</head>
<body>
<div class="head">
    <h1>
        <img style="margin-left: 30px;" src="/img/commonTheme/${sessionScope.InterfaceModel}/icon_noticeMang.png" alt="">党建基础设置
    </h1>
    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm " id="commit" style="font-size:16px;color:#fff;position: absolute;right: 30px;top: 7px;" >
        <i class="layui-icon" style="">&#xe669;</i>
        初始化
    </button>
</div>
<table>
    <tr>
        <td width="400px">申请入党</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="APPLICATION_FORM">
                </li>
            </ul>
            <%--            <select class="fromTrinp" disabled="disabled" name="applicationForm"  type="text">--%>

            <%--            </select>--%>
        </td>
    </tr>
    <tr >
        <td>确定入党积极分子</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="ACTIVIST">
                </li>
            </ul>
            <%--            <select name="activist">--%>
            <%--&lt;%&ndash;                <option value="0">普通审批</option>&ndash;%&gt;--%>
            <%--&lt;%&ndash;                <option value="1">流程审批</option>&ndash;%&gt;--%>
            <%--            </select>--%>
        </td>
    </tr>
    <%-- <tr  >
         <td>入党积极分子第一次到第三次培养教育考察</td>
         <td class="addSelect">
             <ul id="newsFlowBox">
                 <li id="ACTIVIST_REPROT">
                 </li>
             </ul>
 &lt;%&ndash;            <select name="activistReprot">&ndash;%&gt;
 &lt;%&ndash;            </select>&ndash;%&gt;
         </td>
     </tr>
     <tr>
         <td>入党积极分子第四次培养教育考察</td>
         <td class="addSelect">
             <ul id="newsFlowBox">
                 <li id="ACTIVIST_REPROT_FOUR">
                 </li>
             </ul>
 &lt;%&ndash;            <select name="activistReprotFour">&ndash;%&gt;
 &lt;%&ndash;            </select>&ndash;%&gt;
         </td>
     </tr>--%>
    <tr>
        <td>确定发展对象</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="DEVELOP_OBJ">
                </li>
            </ul>
            <%--            <select name="developObj">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <%--   <td>发展对象公示,确定入党介绍人</td>
           <td class="addSelect">
               <ul id="newsFlowBox">
                   <li id="PUBLICITY">
                   </li>
               </ul>
   &lt;%&ndash;            <select name="publicity">&ndash;%&gt;
   &lt;%&ndash;            </select>&ndash;%&gt;
           </td>--%>
    </tr>
    <tr>
        <td>政治审查开展集中培训</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="REVIEW">
                </li>
            </ul>
            <%--            <select name="review">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>支委会审查</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="EXAMINATION">
                </li>
            </ul>
            <%--            <select name="examination">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>支部大会讨论</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="DISCUSS">
                </li>
            </ul>
            <%--            <select name="discuss">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>入党宣誓</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="OATH">
                </li>
            </ul>
            <%--            <select name="oath">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <%-- <tr>
         <td>预备党员第一次到第三次考察培养</td>
         <td class="addSelect">
             <ul id="newsFlowBox">
                 <li id="PROPARTY_REPORT">
                 </li>
             </ul>
 &lt;%&ndash;            <select name="propartyReport">&ndash;%&gt;
 &lt;%&ndash;            </select>&ndash;%&gt;
         </td>
     </tr>
     <tr>
         <td>预备党员第四次考察培养</td>
         <td class="addSelect">
             <ul id="newsFlowBox">
                 <li id="PROPARTY_REPORT_FOUR">
                 </li>
             </ul>
 &lt;%&ndash;            <select name="propartyReportFour">&ndash;%&gt;
 &lt;%&ndash;            </select>&ndash;%&gt;
         </td>
     </tr>--%>
    <tr>
        <td>预备党员转正</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="REGULAR">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>申请入党选择发展阶段</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="SELECT_PHASE">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>入党介绍人</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="RECOMMEND_PERSON">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>培养联系人</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="DEVELOP_CONTACTS">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>入党积极分子培养教育考察</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="ACTIVIST_REPROT">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>预备党员考察培养</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="PROPARTY_REPORT">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td>思想汇报提交</td>
        <td class="addSelect">
            <ul id="newsFlowBox">
                <li id="REPORT">
                </li>
            </ul>
            <%--            <select name="regular">--%>
            <%--            </select>--%>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <div class="btn submitCheck">
                <button class="save">保存</button>
            </div>
        </td>
    </tr>
</table>

<script>
    var arr = [
        "APPLICATION_FORM","ACTIVIST","ACTIVIST_REPROT",/*"ACTIVIST_REPROT_FOUR",*/"DEVELOP_OBJ",
        /*"PUBLICITY",*/"REVIEW","EXAMINATION","DISCUSS","OATH","PROPARTY_REPORT",/*"PROPARTY_REPORT_FOUR",*/
        "REGULAR","SELECT_PHASE","RECOMMEND_PERSON","DEVELOP_CONTACTS","REPORT"
    ]
    //渲染下拉框
    $.ajax({
        url:"/partyMember/getSysPara",
        type:'post',
        dataType:'json',
        success:function(res){
            var data=res.object;
            if(res.flag){
                // var str='<option value="">请选择</option>';
                //$(".addSelect").append('<select class="operation"></select>');
                $(Object.keys(data)).each(function(index,e){
                    $('#'+e).before(initNewsFlowLi(e,data[e]));
                    //console.log("key: " + e + " value: " + data[e]);
                    //$('.operation').eq(index).html('<option value='+data[e]+'></option>');
                });
            }else{
                for(var i = 0 ; i <arr.length;i++){
                    $('#'+arr[i]).before(initNewsFlowLi());
                }


            }
        }
    });
    // $(function() {
    //     $('.set_news_flow').before(initNewsFlowLi());
    // })
    function initNewsFlowLi(ele,flowId) {
        var newsTypeStr = '';

        // newsTypeObj.forEach(function (type) {
        //     newsTypeStr += '<option value="' + type.codeNo + '">' + type.codeName + '</option>';
        // });

        var str =
            '  <div class="search_inline">\n' +
            '                        <input type="text" class="search_inline_item news_flow_id"  dataType="'+(flowId || '')+'" autocomplete="off" name="flowName" placeholder="全部流程">\n' +
            '                        <button class="list" isClick="true"><img src="/img/workflow/work/xiala.png" alt=""></button>\n' +
            '                        <ul class="'+ele+' sel"></ul>\n' +
            '                    </div>'
        var $str = $($.parseHTML(str));

        // if (newsType) {
        //     $str.find('.news_flow_type').val(newsType);
        // }

        // 获取全部流程
        $.ajax({
            url:"/flow/selOneToAllType",
            type:'post',
            dataType:'json',
            success:function(res){
                var data=res.datas;
                //var str='<option value=""><fmt:message code="hr.th.PleaseSelect"/></option>';
                if(res.flag){
                    var flowId = $.GetRequest().flowId;
                    $.each(data,function(i,item){
                        $('.'+ele).append("<li class='ones' style='font-weight:bold;font-size:14px;' id="+item.sortId +"><img src='../../img/data_points.png' style='margin-right: 5px;' alt=''>" + item.sortName + "<li>");
                        $.each(item.flowTypeModels,function(j,v){
                            $('.'+ele).append("<li style='padding-left:10px;cursor:pointer' class='canchoose' value="+v.flowId +">" +v.flowName + "<li>");
                            if(flowId&&flowId==v.flowId){
                                $('[name="flowName"]').val(v.flowName);
                                $('[name="flowName"]').attr('dataType',v.flowId);
                                $('[name="flowName"]').attr('readonly','true');
                                $('.list').hide();
                                return;
                            }
                        })
                        buildNode(1,item.childs,ele);
                    });
                    //下拉框回显
                    $('.search_inline').each(function (index,element) {
                        $(element).find('.canchoose').each(function (i,n) {
                            // $('.search_inline .canchoose').each(function (i,n) {
                            // 	if($(this).attr('value')==$('.search_inline .news_flow_id').eq(index).attr('datatype')){
                            if($(n).attr('value')==$(element).find('.news_flow_id').attr('datatype')){
                                $(n).click();
                                return false;
                            }
                        });
                    })
                }
            }
        });
        return $str;
    }

    $(document).on('click','.list',function (e) {
        e.stopPropagation()
        $('.list').removeAttr('isClick')
        $(this).attr('isClick','true')
        if($(this).attr('isClick')){
            if($(this).next().css('display')!='none'){
                $(this).next().hide()
            }else{
                $(this).next().show()
            }
        }
    })

    $(document).on('click','.sel li',function(e){
        e.stopPropagation()
        if($(this).parent().prev().attr('isClick')){
            if($(this).attr('value')){
                $(this).parent().siblings('[name="flowName"]').val($(this).html())
                $(this).parent().siblings('[name="flowName"]').attr('dataType',$(this).attr('value'))
                /*$('[name="flowName"]').val($(this).html())
                $('[name="flowName"]').attr('dataType',$(this).attr('value'))*/
                $(".sel").hide()
            }else{
                $(".sel").show()
            }
        }
    })

    $(document).click(function(){
        $('.sel').hide()
    })
    function buildNode(len,data,ele){
        var prefix = 10;
        for(var i=0;i<len;i++){
            prefix += 10;
        }

        $.each(data,function(i,item){
            if(0 < item.childs.length){
                $('.'+ele).append("<li style='padding-left:"+(prefix)+"px;font-weight:bold;font-size:14px;' id="+item.sortId +">" + item.sortName + "<li>");
                $.each(item.flowTypeModels,function(j,v){
                    $('.'+ele).append("<li style='padding-left:"+(prefix+10)+"px;cursor:pointer' class='canchoose' value="+v.flowId +">" +  v.flowName + "<li>");
                })
                buildNode(len+1,item.childs,ele);
            }else{
                $('.'+ele).append("<li style='padding-left:"+(prefix)+"px;font-weight:bold;font-size:14px;' id="+item.sortId +">" + item.sortName + "<li>");
                $.each(item.flowTypeModels,function(j,v){
                    $('.'+ele).append("<li style='padding-left:"+(prefix+10)+"px;cursor:pointer' class='canchoose' value="+v.flowId +">" +  v.flowName + "<li>");
                })
            }
        });
    }
    //保存
    $('.save').click(function(){
        var $inp = $("input.search_inline_item");
        for(var i=0;i<$inp.length;i++){
            if($($inp[i]).attr("dataType") == undefined ||$($inp[i]).attr("dataType") == ""){
                layer.msg("流程不能为空");
            }
        }

        var data = {
            APPLICATION_FORM : $('#APPLICATION_FORM').prev("div").find("input").attr("dataType"),
            ACTIVIST : $('#ACTIVIST').prev("div").find("input").attr("dataType"),
            ACTIVIST_REPROT : $('#ACTIVIST_REPROT').prev("div").find("input").attr("dataType"),
            /* ACTIVIST_REPROT_FOUR : $('#ACTIVIST_REPROT_FOUR').prev("div").find("input").attr("dataType"),*/
            DEVELOP_OBJ : $('#DEVELOP_OBJ').prev("div").find("input").attr("dataType"),
            /*PUBLICITY : $('#PUBLICITY').prev("div").find("input").attr("dataType"),*/
            REVIEW : $('#REVIEW').prev("div").find("input").attr("dataType"),
            EXAMINATION : $('#EXAMINATION').prev("div").find("input").attr("dataType"),
            DISCUSS : $('#DISCUSS').prev("div").find("input").attr("dataType"),
            OATH : $('#OATH').prev("div").find("input").attr("dataType"),
            PROPARTY_REPORT : $('#PROPARTY_REPORT').prev("div").find("input").attr("dataType"),
            /*PROPARTY_REPORT_FOUR : $('#PROPARTY_REPORT_FOUR').prev("div").find("input").attr("dataType"),*/
            REGULAR : $('#REGULAR').prev("div").find("input").attr("dataType"),
            SELECT_PHASE : $('#SELECT_PHASE').prev("div").find("input").attr("dataType"),
            RECOMMEND_PERSON : $('#RECOMMEND_PERSON').prev("div").find("input").attr("dataType"),
            DEVELOP_CONTACTS : $('#DEVELOP_CONTACTS').prev("div").find("input").attr("dataType"),
            REPORT : $('#REPORT').prev("div").find("input").attr("dataType")
        }


        $.ajax({
            url:"/partyMember/saveSysPara",
            type:'post',
            dataType:'json',
            data:{
                partySys:JSON.stringify(data),
            },
            success:function(res){
                if(res.flag){
                    layer.msg(res.msg);
                }else{
                    layer.msg(res.msg);
                }
            }
        });
    })
    //初始化
    $('#commit').click(function(){
        layer.confirm('初始化将覆盖所有入党流程且不可逆,是否确认初始化!', {
            btn: ['确认', '取消'],
            icon: 7,
            title: "系统提示"
        }, function () {
            layer.confirm('请再次确认是否初始化!', {
                btn: ['确认', '取消'],
                icon: 7,
                title: "系统提示"
            }, function () {
                var indexPage = layer.load(1);
                $.ajax({
                    url:"/partyMember/updatePartyMemberFlowable",
                    type:'post',
                    dataType:'json',
                    data:{
                    },
                    success:function(res){
                        layer.close(indexPage);
                        if(res.flag){
                            layer.msg(res.msg)
                        }else{
                            layer.msg(res.msg)
                        }
                    }
                });
                layer.close(indexPage);
            }, function () {
                parent.layer.closeAll();
            });
        }, function () {
            parent.layer.closeAll();
        });

    })
</script>
</body>
</html>



